<?php

// 服务器和数据库信息
$servername = "localhost";
$username = "root";
$ppassword = "";
$dbName = "taodb";
$tableName = "users";

//create connection
$conn = new mysqli($servername, $username, $ppassword, $dbName);

//check connection 
if ($conn->connect_error) {
  # code...
  die('fail to connect' . $conn->connect_error);
}

// "INSERT INTO $tableName (username,passwordd,email) VALUES (?,?,?)"
$sql = "SELECT username,passwordd,email FROM $tableName";
$stnt = $conn->prepare($sql);
// $stnt->bind_param('sss',$username,$passwordd,$email);

// $username = "john";
// $passwordd = "doe";
// $email = "faera@fmff.com";
$stnt->execute();

// var_dump($stnt->fetch());
// var_dump($stnt->store_result());
// var_dump($stnt->num_rows);

//单条
// $stnt->bind_result($username,$passwordd,$email);
// $stnt->fetch();
// echo($username.$passwordd.$email);

//全部
$result	= $stnt->get_result();
var_dump($result);
// while($row = $result->fetch_assoc()){
//   var_dump($row);
// }
$row = $result->fetch_all();
var_dump($row);


// echo $stnt->store_result();
// echo "记录个数：".$stnt->num_rows."行<br />";
// var_dump($stnt->result_metadata());

// echo($stmt->insert_id);
// $firstname = "john";
// $lastname = "doe";
// $email = "faera@fmff.com";
// $stnt->execute();

// $firstname = "john";
// $lastname = "doe";
// $email = "faera@fmff.com";
// $stnt->execute();

$stnt->close();
$conn->close();
// $servername = "localhost";
// $username = "root";
// $password = "";
// $dbname = "myDBPDO";

// try {
//     $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
//     // 设置 PDO 错误模式为异常
//     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
//     // 预处理 SQL 并绑定参数
//     $stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, email) 
//     VALUES (:firstname, :lastname, :email)");
//     $stmt->bindParam(':firstname', $firstname);
//     $stmt->bindParam(':lastname', $lastname);
//     $stmt->bindParam(':email', $email);
 
//     // 插入行
//     $firstname = "John";
//     $lastname = "Doe";
//     $email = "john@example.com";
//     // $stmt->execute();
 
//     // 插入其他行
//     $firstname = "Mary";
//     $lastname = "Moe";
//     $email = "mary@example.com";
//     // $stmt->execute();
 
//     // 插入其他行
//     $firstname = "Julie";
//     $lastname = "Dooley";
//     $email = "julie@example.com";
//     $stmt->execute();
 
//     echo "新记录插入成功";
// }
// catch(PDOException $e)
// {
//     echo "Error: " . $e->getMessage();
// }
// $conn = null;



